$(function () {
    
    /*修改产品*/
    $('.submit').on('click',function(){
        //数据验证
        var che =  check();
        if(che == false){
            return false;
        }else{
            intInput();
        }
    });
});

/*获取输入信息*/
function intInput() {
    var cou = 0;
    var para = new Array();
    $('.p_id').each(function () {
        var pro = new Object();
        var p = $(this).parent();
        pro.id = $(this).text();
        p.each(function (k) {
            pro.product_name = $(this).children().children('input[name="p_name"]').val();
            pro.price = $(this).children().children('input[name="p_price"]').val();
            pro.count = $(this).children().children('input[name="p_count"]').val();
        })
        para[cou] = pro;
        cou++;
    });
    if (cou == 0) {
        l_fail('产品不能为空');
        return false;
    } else {
        //提交
        saveConfirm(JSON.stringify(para));
    }
}

/*确认提交*/
function saveConfirm(pa){
    /*console.log(pa);*/
    layui.use(['layer'], function () {
        var layer = layui.layer;
        layer.confirm("确认修改产品?",{"title":"批量修改产品"},function (){
            updatePros(pa)
        },function (){
            layer.close();
        });
    });
}

/*提交订单*/
function updatePros(pa){
    var url = '?m=index-Product&do=updatePros'
    var data = {
        data: pa
    };
    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data: data,
        success: function (res) {
            console.log(res);
            if (res.code == 200)
            {
                var red_url = "?m=index-Product&do=index";
                l_succcess(res.message);
                setTimeout(function(){
                    redir_url(red_url);
                },1000);
            } else
            {
                l_fail(res.message);
            }
        }
    });
}
